package gui;

import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.WindowConstants;

import modifycomponent.JImageViewer;
import controller.LoginController;

public class LoginGUI extends JFrame {
	private static final long serialVersionUID = 0x3BA8CL;

	private JButton btn_exit;
	private JButton btn_login;
	private JLabel lbl_password;
	private JLabel lbl_username;
	private JPanel pn_container;
	private JImageViewer pn_logo;
	private JScrollPane scroll_text;
	private JTextArea ta_detail;
	private JPasswordField tf_password;
	private JTextField tf_username;

	public LoginGUI() {
		init();
	}

	private void init() {
		newComponents();
		setPnLogoLayout();
		setPnContainerLayout();
		setMainLayout();
		
		controller();
	}

	private void newComponents() {
		pn_logo = new JImageViewer();
		pn_container = new JPanel();
		lbl_username = new JLabel();
		tf_username = new JTextField();
		lbl_password = new JLabel();
		tf_password = new JPasswordField();
		btn_exit = new JButton();
		btn_login = new JButton();
		scroll_text = new JScrollPane();
		ta_detail = new JTextArea();
	}

	private void setPnLogoLayout() {
		pn_logo.setBorder(BorderFactory.createTitledBorder(""));
		pn_logo.setFont(new Font("Cordia New", 0, 16));
		pn_logo.setLayout(null);
	}

	private void setPnContainerLayout() {
		pn_container.setBorder(BorderFactory.createTitledBorder(""));
		pn_container.setFont(new Font("Cordia New", 0, 16));
		pn_container.setLayout(null);

		lbl_username.setFont(new Font("Courier New", 0, 16));
		lbl_username.setText("Username");
		pn_container.add(lbl_username);
		lbl_username.setBounds(30, 20, 80, 30);

		tf_username.setFont(new Font("Courier New", 0, 16));
		tf_username.setHorizontalAlignment(JTextField.CENTER);
		pn_container.add(tf_username);
		tf_username.setBounds(120, 20, 230, 30);

		lbl_password.setFont(new Font("Courier New", 0, 16));
		lbl_password.setText("Password");
		pn_container.add(lbl_password);
		lbl_password.setBounds(30, 60, 80, 30);

		tf_password.setFont(new Font("Courier New", 0, 16));
		tf_password.setHorizontalAlignment(JTextField.CENTER);
		pn_container.add(tf_password);
		tf_password.setBounds(120, 60, 230, 30);

		btn_exit.setFont(new Font("Courier New", 0, 16));
		btn_exit.setText("Exit");
		pn_container.add(btn_exit);
		btn_exit.setBounds(200, 110, 150, 40);

		btn_login.setFont(new Font("Courier New", 0, 16));
		btn_login.setText("Login");
		pn_container.add(btn_login);
		btn_login.setBounds(30, 110, 150, 40);
	}

	private void setMainLayout() {
		getContentPane().setLayout(null);

		getContentPane().add(pn_logo);
		pn_logo.setBounds(10, 10, 170, 170);

		getContentPane().add(pn_container);
		pn_container.setBounds(180, 10, 380, 170);

		ta_detail.setColumns(20);
		ta_detail.setRows(5);
		ta_detail.setFont(new Font("Courier New", 0, 22));
		ta_detail.setEditable(false);
		scroll_text.setViewportView(ta_detail);

		getContentPane().add(scroll_text);
		scroll_text.setBounds(10, 182, 550, 250);

		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setIconImage(new ImageIcon("src/icons/small_token_icon.png").getImage());
		setTitle("HQT - Token Login");
		setSize(575, 475);
		setLocationRelativeTo(null);
		setResizable(false);
		setVisible(true);
	}
	
	private void controller(){
		new LoginController(this);
	}
	
	public JButton getBtn_exit() {
		return btn_exit;
	}

	public JButton getBtn_login() {
		return btn_login;
	}

	public JLabel getLbl_password() {
		return lbl_password;
	}

	public JLabel getLbl_username() {
		return lbl_username;
	}

	public JPanel getPn_container() {
		return pn_container;
	}

	public JImageViewer getPn_logo() {
		return pn_logo;
	}

	public JScrollPane getScroll_text() {
		return scroll_text;
	}

	public JTextArea getTa_detail() {
		return ta_detail;
	}

	public JPasswordField getTf_password() {
		return tf_password;
	}

	public JTextField getTf_username() {
		return tf_username;
	}

	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			new LoginGUI();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
